package com.sun.dream.fish.mapstruct;


import com.sun.dream.fish.entity.TNavMetaEntity;
import com.sun.dream.fish.vo.back.MenuVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Description:  菜单VO Mapping
 * Created By ljl on 2023/11/27.
 */
@Mapper
public interface MenuMapBasic {
    MenuMapBasic INSTANCE = Mappers.getMapper(MenuMapBasic.class);

    @Mappings(
            {
                    @Mapping(source = "metaTitle", target = "meta.title"),
                    @Mapping(source = "metaShow", target = "meta.show", qualifiedByName = "mapIntToBoolean"),
                    @Mapping(source = "metaIcon", target = "meta.icon"),
                    @Mapping(source = "metaTarget", target = "meta.target")}
    )
    MenuVO entityToVO(TNavMetaEntity entity);

    @Mappings(
            {
                    @Mapping(target = "metaTitle", source = "meta.title"),
                    @Mapping(target = "metaShow", source = "meta.show", qualifiedByName = "mapBooleanToInt"),
                    @Mapping(target = "metaIcon", source = "meta.icon"),
                    @Mapping(target = "metaTarget", source = "meta.target")}
    )
    TNavMetaEntity voToEntity(MenuVO menuVO);

    List<MenuVO> entityToVO(List<TNavMetaEntity> entityList);

    List<TNavMetaEntity> voToEntity(List<MenuVO> menuVOList);

    @Named("mapIntToBoolean")
    default boolean mapIntToBoolean(int number) {
        return number != 0;
    }

    @Named("mapBooleanToInt")
    default int mapBooleanToInt(boolean show) {
        return show ? 1 : 0;
    }
}
